package com.stms.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.stms.bean.Student;
import com.stms.dao.StudentDao;


@WebServlet("/addStudent")
public class AddStudentServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String stuName = req.getParameter("stuName");
		String className = req.getParameter("className");
		String stuNo = req.getParameter("stuNo");
		String sex = req.getParameter("sex");
		Integer age = Integer.parseInt(req.getParameter("age"));
		String addr = req.getParameter("addr");
		
		Student student = new Student(stuName,className,stuNo,sex,age,addr);
		StudentDao studentDao = new StudentDao();
		int result = studentDao.addStudent(student);
		if (result==1) {
			resp.sendRedirect("success.jsp");
		} else {
			resp.sendRedirect("failure.jsp");
		}
	}
}
